/********************************
 * ETK - Easy ToolKit
 * Copyright (C) 2007-2008 Ekinoks (scv.ekinoks@gmail.com)
 * All rights reserved.
 *
 *    This file is part of ETK.
 *
 *    Foobar is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    Foobar is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Foobar; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ***********************************************************************************/

#ifndef __ETK_WIDGETCONTAINER_H__
#define __ETK_WIDGETCONTAINER_H__

#include <set>

#include "../Widget.h"

#include "../../Render/ToolKit/ToolKit.h"
#include "../../Render/Render.h"

using namespace std;

namespace etk
{
    /// Classe abstract qui modélise un widget container.
    class WidgetContainer : public Widget
    {

        public :
            WidgetContainer(RWidget *rWidget, WidgetContainer * container) : Widget(rWidget, container), myContainer(this)
            {
            }

            //virtual int size_container() const = 0;

            virtual ~WidgetContainer() {print_section("~WidgetContainer");}
        //private :

            //friend class Widget;

            /** Ajouter un widget dans le container
            *   @param widget       : widget a ajouter dans le container
            */
            virtual Widget* add(Widget* widget)
            {
                return myContainer.add(widget);
            }

            /** Suprimer un widget du container
            *   @param widget       : widget a suprimer du container
            */
            virtual void remove(Widget* widget)
            {
                myContainer.remove(widget);
            }
        private :

            /** s'occupe du contenue du container
            *
            */
            class MyContainer
            {
                public :
                    MyContainer(WidgetContainer *me) : me_(me) {}

                    Widget* add(Widget* widget)
                    {
                        listWidget.insert(widget);
                        TOOL_KIT.container_add(me_->getRWidget(), widget->getRWidget());

                        return widget;
                    }

                    void remove(Widget* widget)
                    {
                        start_section("remove");
                        listWidget.erase(widget);
                        end_section("remove");
                    }

                    ~MyContainer()
                    {
                        start_section("~MyContainer");
                        std::set<Widget*>::iterator it;

                        // on supprime automatiquement tout le contenue
                        while((it = listWidget.begin()) != listWidget.end())
                            delete *it;
                        end_section("~MyContainer");
                    }

                private :
                    WidgetContainer *me_;
                    std::set<Widget*> listWidget;

            } myContainer;

    };
}




#endif /* #ifndef __ETK_WIDGETCONTAINER_H__ */

